﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sauces.Bussinees.Entities.Caja;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;

namespace Sauces.Repository.Mapping
{
   public  class DetalleFacturaMap:EntityTypeConfiguration<DetalleFactura>
    {
       public DetalleFacturaMap()
       {
           this.HasKey(p => new { p.item, p.IdFactura });

           this.Property(t => t.item)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

           this.Property(t => t.IdFactura)
               .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

           this.Ignore(f => f.Monto);         

           this.Property(p => p.Cantidad).HasPrecision(9, 2).IsRequired();
           this.Property(p => p.Precio).HasPrecision(9, 2).IsRequired();


           this.ToTable("DetalleFactura");


           this.HasRequired(d => d.Producto).WithMany(t=>t.DetalleFactura).HasForeignKey(d => d.IdProducto);
           this.HasRequired(d => d.Factura).WithMany(t => t.DetalleFactura).HasForeignKey(d => d.IdFactura);
       }
    }
}
